# CameraController.gd
extends Node2D # 或者你的 CameraController 节点实际继承的类型

@onready var player: CharacterBody2D = null # 引用玩家节点
@onready var camera_2d: Camera2D = null # 引用 Camera2D 节点

func _ready():
	#启动
	
	# 查找玩家节点
	player = get_tree().get_first_node_in_group("player")
	# 查找 Camera2D 节点 (假设它是这个 CameraController 的子节点)
	camera_2d = $Camera2D
	camera_2d.make_current()
	# 确保 Camera2D 是当前活动摄像机
	#camera_2d.current = true # 或者在检查器中勾选 Camera2D 的 Current 属性
func _process(delta):
	if camera_2d and player:
		# 将摄像头的世界位置设置为玩家的世界位置
		#camera_2d.global_position = player.global_position
		
		# --- 进阶设置：平滑跟随 ---
		camera_2d.global_position = camera_2d.global_position.lerp(player.global_position, 0.05)
